<?php
namespace Admin\Controller;
use Think\Controller;
class IndexController extends Controller {
    public function index(){
         $name= I("post.name");
         $pwd=  I("post.pwd");
          $cid=cookie('uid');
         if(empty($cid)){
              $M = M('admin','ny_','newyear');
              $where['name'] = $name;
              $where['pwd'] = $pwd;
              // 把查询条件传入查询方法
              $result= $M->where($where)->find();
              if($result){
                    cookie('uid',$result['id'],3600); // 指定cookie保存时间
                    cookie('name',$result['name'],3600); // 指定cookie保存时间
                    cookie('pwd',$result['pwd'],3600); // 指定cookie保存时间
                    $this->assign('name',$result['name']);
                    $this->display("Index");
              }else{
                    $this->display("login");
              }
        }else{
               $this->assign('name',cookie('name'));
               $this->display("Index");
        }

    }

     public  function  build(){

           $M = M('lotto','ny_prize_','newyear');
           $prize =$M->order('v asc')->select();
           $data['rows']=$prize;
           $this->ajaxReturn($data);
     }

      public  function  updatePwd(){
             $pwd= I('post.newPwd');
             $cid=cookie('uid');
             if(empty($cid)){
               $data['content']="尚未登录！";
               $this->ajaxReturn($data);
             }
            $M = M('admin','ny_','newyear');
            $where['id'] = cookie('uid');
            $where['pwd'] = $pwd;
            $M->save($where);
            $data['content']="修改成功！";
            $this->ajaxReturn($data);
      }

      public  function  loginout(){
            cookie('uid',null);
            cookie('name',null);
            cookie('pwd',null);
            $this->display("login");
      }
      /*
       * 负责转发各种窗口
       */
      public  function  op(){
            $type= I('get.optype');
            $this->assign('optype',$type);
            $allScore= jisuanAllScore();
            if($type=="singlerPrize"){
            $M = M('exchange','ny_prize_','newyear');
            $prize =$M->order('score asc')->select();
            $html="";
            foreach($prize as $value){
                  $html.=" <option value=".$value['id'].">".$value['pname']."</option>";
            }
        }
            if( $type=="singlerLottoPrize"){
                  $M2 = M('lotto','ny_prize_','newyear');
                  $prize2 =$M2->select();
                  $html2="";
                  foreach($prize2 as $value){
                        $html2.=" <option value=".$value['id'].">".$value['pname']."</option>";
                  }
            }
            $this->assign('select',$html);
            $this->assign('Lottoselect',$html2);
            $this->assign('allScore',$allScore);
            $this->display("dataGird");
      }
      //个人签到
      public  function  SignLog(){
            $ModAct = M('user','ny_','newyear');
            //当前第几页
            $pagenum=isset($_POST['page'])? intval($_POST['page']):1;
            //每页显示的记录数
            $pagesize=isset($_POST['rows'])? intval($_POST['rows']):10;

            $list=$ModAct->limit(($pagenum-1)*$pagesize.','.$pagesize)->select();
            $total=$ModAct->count();  //查询满足条件的总记录数
            foreach($list as $key=>$value){
                  $data[$key]['uid']=$value['id'];
                  $data[$key]['count']=GetUserSignCount($value['id']);
            }
            $Json['total']=$total;
            $Json['rows']= $data;
            $this->ajaxReturn($Json);

      }

      public  function  LoginList(){
            $ModAct = M('log','ny_login_','newyear');
            //当前第几页
            $pagenum=isset($_POST['page'])? intval($_POST['page']):1;
            //每页显示的记录数
            $pagesize=isset($_POST['rows'])? intval($_POST['rows']):10;

            $list=$ModAct->limit(($pagenum-1)*$pagesize.','.$pagesize)->order('addtime')->select();
            $total=$ModAct->count();  //查询满足条件的总记录数
            foreach($list as $key=>$value){
                  $data2[$key]['uid']=$value['uid'];
                  $data2[$key]['addtime']=date('Y-m-d h:m:s',$value['addtime']);
                  $data2[$key]['strip']=$value['strip'];
            }
            $data['total']=$total;
            $data['rows']= $data2;
            $this->ajaxReturn($data);
      }

      public  function  show_got_duihuan_prize(){
            $type=I("get.type");
            $ModAct = M('prize','ny_act_','newyear');
            //当前第几页
            $pagenum=isset($_POST['page'])? intval($_POST['page']):1;
            //每页显示的记录数
            $pagesize=isset($_POST['rows'])? intval($_POST['rows']):10;
            $where['type']=$type;
            $list=$ModAct->where("type=".$type)->limit(($pagenum-1)*$pagesize.','.$pagesize)->order('subtime')->select();
            $totle=$ModAct->where("type=".$type)->select();
            $total=count($totle);  //查询满足条件的总记录数
            foreach($list as $key=>$val){
                  $user=  getUserByUid($val['uid']);
                  if($type==2){
                        $prize=  getLottoPrizeByPid($val['pid']);
                  }
                  if($type==1){
                         $prize=  getDuiHuanPrizeByPid($val['pid']);
                  }
                  $data[$key]['id']= $val['id'];
                  $data[$key]['uid']= $val['uid'];
                  if($user){
                        $data[$key]['username']=$user['user_turename'] ;
                        $data[$key]['tel']=$user['phone'] ;
                        $data[$key]['address']=$user['add_p'].$user['add_c'].$user['address'] ;
                  }else{
                        $data[$key]['username']="无数据" ;
                        $data[$key]['tel']="无数据" ;
                        $data[$key]['address']="无数据" ;
                  }
                  if($prize){
                        $data[$key]['pname']=$prize['pname'] ;
                  }
                  $data[$key]['ismobie']= $val['ismobie'];
                  $data[$key]['addtime']= date("Y-m-d h:i:sa",$val['subtime']);
            }
            $result['total']=$total;
            $result['rows']= $data;
            $this->ajaxReturn($result);
      }
      public  function  duihuan(){
            //ny_prize_exchange
            $ModAct = M('exchange','ny_prize_','newyear');
            $list=$ModAct->order('id')->select();
            $total=$ModAct->count();  //查询满足条件的总记录数
            $data['total']=$total;
            $data['rows']= $list;
            $this->ajaxReturn($data);
      }
      public  function  lotto_prize(){
            //ny_prize_exchange
            $ModAct = M('lotto','ny_prize_','newyear');
            $list=$ModAct->order('id')->select();
            $total=$ModAct->count();  //查询满足条件的总记录数
            $data['total']=$total;
            $data['rows']= $list;
            $this->ajaxReturn($data);
      }

      /**
       *
       * 保存奖品信息
       * display
       */
      public  function  SavePrizeInfo(){
            $data= I('Post.rowData');
            $ModAct = M('exchange','ny_prize_','newyear');
            //记录 用户 信息
            if($data['id']){
                  $actUser['id'] = $data['id'];
                  $actUser['num'] = $data['num'];
                  $actUser['left'] = $data['left'];
                  $actUser['pname'] = $data['pname'];
                  $actUser['score'] = $data['score'];
                  $actUser['numperday']=$data['numperday'];
                  $actUser['explain']=$data['explain'];
                  $actUser['is_money_prize']=$data['is_money_prize'];
                  $actUser['item_id']=$data['item_id'];
                  $actUser['is_code_prize']=$data['is_code_prize'];
                  $actUser['is_url_prize']=$data['is_url_prize'];
                  $result=  $ModAct->save($actUser);
                  if($result>0){
                        $ReturnData['content']='修改成功！';
                  }else{
                        $ReturnData['content']='修改失败！';
                  }
            }else{
                  $actUser['type'] = 1;
                  $actUser['source'] = "积分兑换";
                  $actUser['num'] = $data['num'];
                  $actUser['left'] = $data['left'];
                  $actUser['pname'] = $data['pname'];
                  $actUser['score'] = $data['score'];
                  $actUser['numperday']=$data['numperday'];
                  $actUser['explain']=$data['explain'];
                  $actUser['is_money_prize']=$data['is_money_prize'];
                  $actUser['item_id']=$data['item_id'];
                  $actUser['is_code_prize']=$data['is_code_prize'];
                  $actUser['is_url_prize']=$data['is_url_prize'];
                  $result=  $ModAct->add($actUser);
                  if($result>0){
                        $ReturnData['content']='添加成功！';
                  }else{
                        $ReturnData['content']='添加失败！';
                  }

            }
            $this->ajaxReturn($ReturnData);
      }

      /**
       *
       * 保存抽奖奖品信息
       * display
       */
      public  function  Savelotto_prizeInfo(){

            $data= I('Post.rowData');
            $ModAct = M('lotto','ny_prize_','newyear');
            //记录 用户 信息
            if($data['id']==""){
                  $actUser['num'] = $data['num'];
                  $actUser['left'] = $data['left'];
                  $actUser['pname'] = $data['pname'];
                  $actUser['numperday']=$data['numperday'];
                  $actUser['is_money_prize']=$data['is_money_prize'];
                  $actUser['is_url_prize']=$data['is_url_prize'];
                  $actUser['is_code_prize']=$data['is_code_prize'];
                  $actUser['explain']=$data['explain'];
                  $actUser['v']=$data['v'];
                  $actUser['item_id']=$data['item_id'];
                  $result=  $ModAct->add($actUser);
                  if($result>0){
                        $ReturnData['content']='add成功！';
                  }else{
                        $ReturnData['content']='add失败！';
                  }

            }else{
                  $actUser['id'] = $data['id'];
                  $actUser['num'] = $data['num'];
                  $actUser['left'] = $data['left'];
                  $actUser['pname'] = $data['pname'];
                  $actUser['is_money_prize']=$data['is_money_prize'];
                  $actUser['is_url_prize']=$data['is_url_prize'];
                  $actUser['is_code_prize']=$data['is_code_prize'];
                  $actUser['explain']=$data['explain'];
                  $actUser['numperday']=$data['numperday'];
                  $actUser['v']=$data['v'];
                  $actUser['item_id']=$data['item_id'];
                  $result=  $ModAct->save($actUser);
                  if($result>0){
                        $ReturnData['content']='修改成功！';
                  }else{
                        $ReturnData['content']='修改失败！';
                  }
            }

            $this->ajaxReturn($ReturnData);
      }
      public function upload(){

            $upload = new \Think\Upload();// 实例化上传类
            $upload->maxSize   =     3145728 ;// 设置附件上传大小
            $upload->exts      =     array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
            $upload->rootPath  =     'Public/'; // 设置附件上传根目录
            $upload->savePath  =     'img_prize/'; // 设置附件上传（子）目录
            // 上传文件
            $info   =   $upload->upload();

            if(!$info) {// 上传错误提示错误信息
                  $this->error($upload->getError());
            }else{// 上传成功
                  $id= I('get.rowindex');
                  $url=  $info['imagess']['savepath'].$info['imagess']['savename'];
                  $this->SavePrizeInfo2($id,$url);
                  $this->success('上传成功！');
            }

      }
//上传抽奖的图片
      public function upload2(){

            $upload = new \Think\Upload();// 实例化上传类
            $upload->maxSize   =     3145728 ;// 设置附件上传大小
            $upload->exts      =     array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
            $upload->rootPath  =     'Public/'; // 设置附件上传根目录
            $upload->savePath  =     'img_prize/'; // 设置附件上传（子）目录
            // 上传文件
            $info   =   $upload->upload();

            if(!$info) {// 上传错误提示错误信息
                  $this->error($upload->getError());
            }else{// 上传成功
                  $id= I('get.rowindex');
                  $url=  $info['imagess']['savepath'].$info['imagess']['savename'];
                  $this->SavePrizeInfo3($id,$url);
                  $this->success('上传图片成功！');
            }

      }
      /**
       *
       * 保存奖品信息
       * display
       */
      public  function  SavePrizeInfo2($id,$img){

            $ModAct = M('exchange','ny_prize_','newyear');
            //记录 用户 信息

                  $actUser['id'] = $id;
                  $actUser['image'] = $img;
                  $result=  $ModAct->save($actUser);

      }
      /**
       *
       * 保存奖品信息
       * display
       */
      public  function  SavePrizeInfo3($id,$img){

            $ModAct = M('lotto','ny_prize_','newyear');
            //记录 用户 信息

            $actUser['id'] = $id;
            $actUser['image'] = $img;
            $result=  $ModAct->save($actUser);

      }

      /**
       *登录用户list
       */
    public  function User_list(){
            $ModAct = M('user','ny_','newyear');
            //当前第几页
            $pagenum=isset($_POST['page'])? intval($_POST['page']):1;
            //每页显示的记录数
            $pagesize=isset($_POST['rows'])? intval($_POST['rows']):10;

            $list=$ModAct->limit(($pagenum-1)*$pagesize.','.$pagesize)->order('addtime')->select();
            $total=$ModAct->count();  //查询满足条件的总记录数

            foreach($list as $key=>$value){
                  $datas[$key]['id']=$value['id'];
                  $datas[$key]['email']=$value['email'];
                  $datas[$key]['user_name']=$value['user_name'];
                  $datas[$key]['user_turename']=$value['user_turename'];
                  $datas[$key]['phone']=$value['phone'];
                  $datas[$key]['add_p']=$value['add_p'];
                  $datas[$key]['add_c']=$value['add_c'];
                  $datas[$key]['address']=$value['address'];
                  $datas[$key]['currentScore']=GetUserSocreByUid($value['id']);
                  $datas[$key]['UsedScore']=jisuanScore($value['id']);
//                  $datas[$int]['prizelist']=jisuanPrize($value['id']);
            }

            $data['total']=$total;
            $data['rows']= $datas;
            $this->ajaxReturn($data);
      }

   //统计登录次数
      public  function  login_times_list(){

            // 开始的时间戳
            $startUnix = 1482508800; // 2016-12-24 00:00:00
            // 结束的时间戳
            $endUnix = 1487519999;   // 2017-2-19 23:59:59
            $M = M('log','ny_login_','newyear');
            $int=0;
            for($i = $startUnix; $i < $endUnix; $i += 86400) {  // 86400为1天的秒数
                  $wherePrize['addtime'] = array(array('EGT',$i),array('ELT',$i + 86400),'AND');
                  $res=$M->where($wherePrize)->select();
                  if(count($res)>0){
                        $data[$int]['count']=count($res);
                        $data[$int]['time']=date('Y-m-d',$i);
                        $int=$int+1;
                  }
            }
            $data2['rows']=$data;
            $this->ajaxReturn($data2);


      }
      /*
/*
*     d导出中奖名单(代金券)
*/
      public  function  exportUserQuan(){
            $type=I("get.type");
            if($type==1){
                  $ModAct = M('user','ny_','newyear');
                  $list=$ModAct->field('uid,email,user_name,user_turename,phone,add_p,add_c,address')->join("ny_act_prize on ny_act_prize.uid=ny_user.id",'RIGHT')->where('pid  in (7,8,12,13) and type=1')->group('uid')->order('addtime')->select();
                  $data="";
                  foreach($list as $key=>$value){
                        \Think\Log::write('用户id-'.$value['uid'].'用户名'.$value['user_name'].'执行了'.($key+1).'次', 'INFO');
                        $data[$key]['id']=$value['uid'];
                        $data[$key]['email']=$value['email'];
                        $data[$key]['user_name']=$value['user_name'];
                        $data[$key]['user_turename']=$value['user_turename'];
                        $data[$key]['phone']=$value['phone'];
//                        $data[$key]['address']=$value['add_p'].$value['add_c'].$value['address'];
                        $data[$key]['prizelist']=jisuanPrizeQuan($value['uid']);
//                  if(jisuanPrize($value['uid'])==""){
//                         unset($data[$key]);
//                  }
                  }
                  $header['A1']='用户id';
                  $header['B1']='邮箱';
                  $header['C1']='昵称';
                  $header['D1']='姓名';
                  $header['E1']='手机号';
                  $header['F1']='详细地址';
                  $header['G1']='兑换总积分';
                  $header['H1']='所有奖品';
//            create_csv($data,$header,"ExchangePrizeUserInfo.csv");
                  create_PrizeQuan_xls($data,$header,"ExchangePrizeQuanUserInfo.xls");
            }
            if($type==2){
                  $ModAct = M('user','ny_','newyear');
                  $list=$ModAct->field('uid,email,user_name,user_turename,phone,add_p,add_c,address')->join("ny_act_prize on ny_act_prize.uid=ny_user.id",'RIGHT')->where('pid  in (6,7,8,9,10) and type=2')->group('uid')->order('addtime')->select();
                  $data="";
                  foreach($list as $key=>$value){
                        \Think\Log::write('用户id-'.$value['uid'].'用户名'.$value['user_name'].'执行了'.($key+1).'次', 'INFO');
                        $data[$key]['id']=$value['uid'];
                        $data[$key]['email']=$value['email'];
                        $data[$key]['user_name']=$value['user_name'];
                        $data[$key]['user_turename']=$value['user_turename'];
                        $data[$key]['phone']=$value['phone'];
                        $data[$key]['address']=$value['add_p'].$value['add_c'].$value['address'];
                        $data[$key]['prizelist']=jisuanLottoPrizeQuan($value['uid']);
//
                  }
                  $header['A1']='用户id';
                  $header['B1']='邮箱';
                  $header['C1']='昵称';
                  $header['D1']='姓名';
                  $header['E1']='手机号';
                  $header['F1']='详细地址';
                  $header['H1']='所有奖品';
//            create_csv($data,$header,"ExchangePrizeUserInfo.csv");
                  create_lottoQuan_xls($data,$header,"LottoPrizeQuanUserInfo.xls");


            }


      }
      /*
      /*
 *     d导出中奖名单
 */
      public  function  exportDuiUser(){
            $ModAct = M('user','ny_','newyear');
            $list=$ModAct->field('uid,email,user_name,user_turename,phone,add_p,add_c,address')->join("ny_act_prize on ny_act_prize.uid=ny_user.id",'RIGHT')->where('pid not in (7,8,12,13) and type=1')->group('uid')->order('addtime')->select();
            $data="";
            foreach($list as $key=>$value){
                  \Think\Log::write('用户id-'.$value['uid'].'用户名'.$value['user_name'].'执行了'.($key+1).'次', 'INFO');
                  $data[$key]['id']=$value['uid'];
                  $data[$key]['email']=$value['email'];
                  $data[$key]['user_name']=$value['user_name'];
                  $data[$key]['user_turename']=$value['user_turename'];
                  $data[$key]['phone']=$value['phone'];
                  $data[$key]['address']=$value['add_p'].$value['add_c'].$value['address'];
                  $data[$key]['socre']=jisuanScore($value['uid']);
                  $data[$key]['prizelist']=jisuanPrize($value['uid']);
//                  if(jisuanPrize($value['uid'])==""){
//                         unset($data[$key]);
//                  }
            }
            $header['A1']='用户id';
            $header['B1']='邮箱';
            $header['C1']='昵称';
            $header['D1']='姓名';
            $header['E1']='手机号';
            $header['F1']='详细地址';
            $header['G1']='兑换总积分';
            $header['H1']='所有奖品';
//            create_csv($data,$header,"ExchangePrizeUserInfo.csv");
            create_xls($data,$header,"ExchangePrizeUserInfo.xls");
      }

      public  function  exportlottoUser(){
            $ModAct = M('user','ny_','newyear');
            $list=$ModAct->field('uid,email,user_name,user_turename,phone,add_p,add_c,address')->join("ny_act_prize on ny_act_prize.uid=ny_user.id",'RIGHT')->where('pid not in (6,7,8,9,10) and type=2')->group('uid')->order('addtime')->select();
            $data="";
            foreach($list as $key=>$value){
                  \Think\Log::write('用户id-'.$value['uid'].'用户名'.$value['user_name'].'执行了'.($key+1).'次', 'INFO');
                  $data[$key]['id']=$value['uid'];
                  $data[$key]['email']=$value['email'];
                  $data[$key]['user_name']=$value['user_name'];
                  $data[$key]['user_turename']=$value['user_turename'];
                  $data[$key]['phone']=$value['phone'];
                  $data[$key]['address']=$value['add_p'].$value['add_c'].$value['address'];
                  $data[$key]['prizelist']=jisuanLottoPrize($value['uid']);
//                  if(jisuanLottoPrize($value['uid'])==""){
//                        unset($data[$key]);
//                  }
            }
            $header['A1']='用户id';
            $header['B1']='邮箱';
            $header['C1']='昵称';
            $header['D1']='姓名';
            $header['E1']='手机号';
            $header['F1']='详细地址';
            $header['H1']='所有奖品';
//            create_csv($data,$header,"ExchangePrizeUserInfo.csv");
            create_lotto_xls($data,$header,"LottoPrizeUserInfo.xls");
      }

      public  function  exportUser(){
            $ModAct = M('user','ny_','newyear');
            $list=$ModAct->order('addtime')->select();
            $data="";
            foreach($list as $key=>$value){
                  $data[$key]['id']=$value['id'];
                  $data[$key]['email']=$value['email'];
                  $data[$key]['user_name']=$value['user_name'];
                  $data[$key]['user_turename']=$value['user_turename'];
                  $data[$key]['phone']=$value['phone'];
                  $data[$key]['address']=$value['add_p'].$value['add_c'].$value['address'];
                  $data[$key]['currentScore']=GetUserSocreByUid($value['id']);
                  $data[$key]['UsedScore']=jisuanScore($value['id']);
            }
            $header['A1']='uid';
            $header['B1']='邮箱';
            $header['C1']='昵称';
            $header['D1']='姓名';
            $header['E1']='手机号';
            $header['F1']='详细地址';
            $header['G1']='当前积分';
            $header['H1']='使用积分';
//            create_csv($data,$header,"ExchangePrizeUserInfo.csv");
            create_User_xls($data,$header,"UserInfo.xls");


      }


      public  function  singlerPrize(){

            $pid= I('post.pid');
            // 开始的时间戳
            $startUnix = 1482508800; // 2016-12-24 00:00:00
            // 结束的时间戳
//            $endUnix = 1485273600;   // 2017-1-25 23:59:59
            $endUnix = strtotime(date("Y-m-d") ."11:59:59"); // 今天
            $nowDate=time();
            if($nowDate>$endUnix){
                  $endUnix = strtotime(date("Y-m-d", strtotime("+1 day")) ."11:59:59"); // 明天
            }
            $M = M('prize','ny_act_','newyear');
            $int=0;
            $wherePrize['pid'] =$pid!=""?$pid:1;
            $wherePrize['type'] =1;
            $wherePrize['subtime'] = array(array('EGT',$startUnix),array('ELT',$startUnix + 86400 +43200),'AND');
            $result = $M->where($wherePrize)->group('pid')->field('pid,count(*)')->select();
            $prize=  GetMyPrizeBypid($pid!=""?$pid:1);
            $data[$int]['count']=$result[0]['count(*)']==null?0:$result[0]['count(*)'];
            $data[$int]['pname']=$prize['pname'];
            $data[$int]['time']=date('Y-m-d',$startUnix);
            $startUnix = $startUnix + 86400 +43200;
            $count=$data[$int]['count'];
            $int=$int+1;
            for($i = $startUnix; $i < $endUnix; $i += 86400){  // 86400为1天的秒数
                  $wherePrize['pid'] =$pid!=""?$pid:1;
                  $wherePrize['type'] =1;
                  $wherePrize['subtime'] = array(array('EGT',$i),array('ELT',$i + 86399),'AND');
                  $result = $M->where($wherePrize)->group('pid')->field('pid,count(*)')->select();
//                  if($result[0]['count(*)']<>""){
                  $prize=  GetMyPrizeBypid($pid!=""?$pid:1);
                  $data[$int]['count']=$result[0]['count(*)']==null?0:$result[0]['count(*)'];
                  $data[$int]['pname']=$prize['pname'];
                  $data[$int]['time']=date('Y-m-d',$i);
                  $count +=$data[$int]['count'];
                  $int=$int+1;
//                  }
            }
            $data[$int]['count']=$count;
            $data[$int]['pname']="总数";
            $data[$int]['time']=date('Y-m-d',$i);
            $data2['rows']=$data;
            $this->ajaxReturn($data2);

      }

      public  function  singlerLottoPrize(){

            $pid= I('post.pid');
            // 开始的时间戳
            $startUnix = 1484064000; // 2016-12-24 00:00:00
            // 结束的时间戳
//            $endUnix = 1485273600;   // 2017-1-25 23:59:59
            $endUnix = strtotime(date("Y-m-d") ."11:59:59"); // 今天
            $nowDate=time();
            if($nowDate>$endUnix){
                  $endUnix = strtotime(date("Y-m-d", strtotime("+1 day")) ."11:59:59"); // 明天
            }
            $M = M('prize','ny_act_','newyear');
            $int=0;
            $wherePrize['pid'] =$pid!=""?$pid:1;
            $wherePrize['type'] =2;
            $wherePrize['subtime'] = array(array('EGT',$startUnix),array('ELT',$startUnix + 86400 +43200),'AND');
            $result = $M->where($wherePrize)->group('pid')->field('pid,count(*)')->select();
            $prize=  GetMyLottoPrizeBypid($pid!=""?$pid:1);
            $data[$int]['count']=$result[0]['count(*)']==null?0:$result[0]['count(*)'];
            $data[$int]['pname']=$prize['pname'];
            $data[$int]['time']=date('Y-m-d',$startUnix);
            $startUnix = $startUnix + 86400 +43200;
            $count=$data[$int]['count'];
            $int=$int+1;
            for($i = $startUnix; $i < $endUnix; $i += 86400){  // 86400为1天的秒数
                  $wherePrize['pid'] =$pid!=""?$pid:1;
                  $wherePrize['type'] =2;
                  $wherePrize['subtime'] = array(array('EGT',$i),array('ELT',$i + 86399),'AND');
                  $result = $M->where($wherePrize)->group('pid')->field('pid,count(*)')->select();
//                  if($result[0]['count(*)']<>""){
                  $prize=  GetMyLottoPrizeBypid($pid!=""?$pid:1);
                  $data[$int]['count']=$result[0]['count(*)']==null?0:$result[0]['count(*)'];
                  $data[$int]['pname']=$prize['pname'];
                  $data[$int]['time']=date('Y-m-d',$i);
                  $count +=$data[$int]['count'];
                  $int=$int+1;
//                  }
            }
            $data[$int]['count']=$count;
            $data[$int]['pname']="总数";
            $data[$int]['time']=date('Y-m-d',$i);
            $data2['rows']=$data;
            $this->ajaxReturn($data2);

      }
}